/**
 * Copyright (c) 2018-2022, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: process asm 
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2022-05-15     JasonHu           Init
 */

#define __ASSEMBLY__
#include <base/defines.h>

.code32
.text

/*
 * void NX_HalProcessEnterUserMode(frame);
 */
NX_FUNC(NX_HalProcessEnterUserMode)
    movl 0x4(%esp), %esp
    addl $4,%esp    // skip intr no
    popal
    popl %gs
    popl %fs
    popl %es
    popl %ds
    addl $4, %esp   // skip error code
    iret    // enter to user mode
NX_ENDFUNC(NX_HalProcessEnterUserMode)

.align 4

NX_FUNC(NX_HalUserThreadReturnCodeBegin)
    movl %eax, %ebx  // ebx = eax = exit code 
    movl $48, %eax   // eax = 48, SysThreadExit
    int $0x80
NX_ENDFUNC(NX_HalUserThreadReturnCodeBegin)

.align 4
NX_FUNC(NX_HalUserThreadReturnCodeEnd)
NX_ENDFUNC(NX_HalUserThreadReturnCodeEnd)

.align 4

NX_FUNC(NX_HalSignalReturnCodeBegin)
    movl $0xF00000, %eax // eax = SysSignalReturn, hide for user
    int $0x80
NX_ENDFUNC(NX_HalSignalReturnCodeBegin)

.align 4
NX_FUNC(NX_HalSignalReturnCodeEnd)
NX_ENDFUNC(NX_HalSignalReturnCodeEnd)
